package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.NewGoodsActivity;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.NewGoodsBean;

import java.util.List;

import retrofit2.Call;

/**
 * Created by ${wenping} on 6/16/2017.
 */

public class NewGoodsPresenter extends BasePresenter {

    private NewGoodsActivity mNewGoodsActivity;
    private boolean openLog = true;
    private List<NewGoodsBean.ProductListBean> mGoodsProductList;

    public NewGoodsPresenter(NewGoodsActivity newGoodsActivity) {
        mNewGoodsActivity = newGoodsActivity;
    }


    public void loadNewGoods(){
        Call<NewGoodsBean> newGoodsBeanCall = mApiService.getNewGoods("1", "10", "saleDown");
        newGoodsBeanCall.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        if (openLog) {
            Log.e(TAG, "onServerBug ");
        }
    }

    @Override
    protected void onConnectError(String message) {
        if (openLog) {
            Log.e(TAG, "onConnectError ");
        }
    }

    private static final String TAG = "NewGoodsPresenter";
    @Override
    protected void onSuccess(BaseBean bean) {
        if (openLog) {
            Log.e(TAG, "onSuccess ");
            NewGoodsBean newGoodsBean = (NewGoodsBean) bean;
            if (newGoodsBean!=null){
                mGoodsProductList = newGoodsBean.getProductList();
                mNewGoodsActivity.onLimitBuySuccess(mGoodsProductList);
            }else{
                Log.e(TAG, "数据请求失败"+newGoodsBean.getError()+";"+newGoodsBean.getError_code());

            }
        }
    }
}
